/*
 * @Author: xishanxu
 * @LastEditors  : xisuanxu
 * @LastEditTime : 2020-01-10 23:36:09
 */
import { testAjax } from '@/utils/request';

interface IGetBanner {
  page: number;
  size: number;
}

interface IGetIcons {
  page: number;
  size: number;
  role_id: number;
}

interface IGetPosts {
  page: number;
  size: number;
  type: number;
}

interface IIcon {
  role_id: number;
  image_id: number;
  title: string;
  url: string;
  sort: number;
  status: boolean;
}

interface IEditIcon extends IIcon {
  id: number;
}

// 获取Icon列表
export function getIcons(params: IGetIcons) {
  return testAjax({
    method: 'GET',
    url: '/admin/icons',
    params,
  });
}

// 新增icon
export function addIcon(data: IIcon) {
  return testAjax({
    method: 'POST',
    url: '/admin/icons',
    data,
  });
}

// 修改icon
export function editIcon(data: IEditIcon) {
  return testAjax({
    method: 'PUT',
    url: `/admin/icons/${data.id}`,
    data,
  });
}

// 删除icon
export function deleteIcon(data: IEditIcon) {
  return testAjax({
    method: 'DELETE',
    url: `/admin/icons/${data.id}`,
    data,
  });
}
// ----------------------------------------------------------------
// 获取banners列表
export function getBanners(params: IGetBanner) {
  return testAjax({
    method: 'GET',
    url: '/admin/banners',
    params,
  });
}

// 新增banners
export function addBanner(data: IIcon) {
  return testAjax({
    method: 'POST',
    url: '/admin/banners',
    data,
  });
}

// 修改banners
export function editBanner(data: IEditIcon) {
  return testAjax({
    method: 'PUT',
    url: `/admin/banners/${data.id}`,
    data,
  });
}

// 删除banners
export function deleteBanner(data: IEditIcon) {
  return testAjax({
    method: 'DELETE',
    url: `/admin/banners/${data.id}`,
    data,
  });
}

// ----------------------------------------------------------------
// 获取Posts列表
export function getPosts(params: IGetPosts) {
  return testAjax({
    method: 'GET',
    url: '/admin/posts',
    params,
  });
}

// 新增posts
export function addPosts(data: IIcon) {
  return testAjax({
    method: 'POST',
    url: '/admin/posts',
    data,
  });
}

// 修改posts
export function editPosts(data: IEditIcon) {
  return testAjax({
    method: 'PUT',
    url: `/admin/posts/${data.id}`,
    data,
  });
}

// 删除posts
export function deletePosts(data: IEditIcon) {
  return testAjax({
    method: 'DELETE',
    url: `/admin/posts/${data.id}`,
    data,
  });
}
